<?php 
	session_start();
	$user_name = "";
	$user_pass = "";
	$money = "";
	//if(isset($_SESSION['username'])){
		//header('Location: index.php');
		//exit();
	//}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1251">
<title>Registration form</title>
</head>
<body>
<?php
	if(isset($_POST['register'])){
		
		$user_name = $_POST['user_name'];
		$user_pass = md5($_POST['user_pass']);
		$money = $_POST['money'];
		$db_connect = mysqli_connect("localhost", "root", "root", "tractor");
		$query1 = "SELECT user_name
					FROM user
					WHERE user_name = '$user_name'";
		$result1 = mysqli_query($db_connect, $query1);
		if(mysqli_num_rows($result1) > 0){
			
			echo "<p>Username is not available</p>";
		}else{
			$_SESSION['username'] = $user_name;
			$query = "INSERT INTO user(user_name, user_pass, money)
							VALUES('$user_name', '$user_pass', '$money')";
			$result = mysqli_query($db_connect, $query);
			header('Location: index.php');
		}
		mysqli_close($db_connect);
	}
?>
<form method="post">
	<table>
		<tr><td>Name:</td><td><input type="text" name="user_name"/></td><tr>
		<tr><td>Password:</td><td><input type="password" name="user_pass"/></td><tr>
		<tr><td>Money:</td><td><input type="text" name="money"/></td><tr>
		<tr><td><input type="submit" name="register" value="Register"/></td><tr>
	</table>
</form>
</body>
</html>